package com.bj58.groupbuy.action.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bj58.groupbuy.action.model.Menu;
import com.bj58.groupbuy.action.model.NewBelongCate;
import com.bj58.groupbuy.action.model.NewDisplayCate;
import com.bj58.groupbuy.action.service.MenuService;
import com.bj58.groupbuy.action.service.NetFlowSourceService;
import com.bj58.groupbuy.action.service.NewBelongCateService;
import com.bj58.groupbuy.action.service.NewDisplayCateService;
import com.bj58.groupbuy.service.locator.ServiceLocator;


/**缓存 及 硬编码类型的全局共用变量
 * @author huangliang
 *
 */
public class MyStore {
	private NewDisplayCateService newDisplayCateService = ServiceLocator.get(NewDisplayCateService.class);
	private NewBelongCateService newBelongCateService = ServiceLocator.get(NewBelongCateService.class);
	
	public static final String admin = "allHL";
	public static HashMap<String,String> dpCC = new HashMap<String, String>();//展现类别 频道 - 品类对应
	public static HashMap<String,String> bcCC = new HashMap<String, String>();//归属类别 频道 - 品类对应
	
//	//自定义报表查询count数缓存Map
//	public static HashMap<String,Integer>  countTableMap = new HashMap<String, Integer>();

	
	//中小城市
	public static final String zscitys = 
		"'菏泽','临汾','枣庄','晋城','张家口','大同','濮阳','周口','滨州','绥化','丹东','揭阳','盘锦','承德','葫芦岛','宜宾','运城'," +
		"'长治','晋中','四平','遂宁','清远','鸡西','宿迁','白城','朝阳','驻马店','达州','辽阳','本溪','茂名','贵港','安康','萍乡'," +
		"'通辽','铁岭','乌海','鄂州','随州','韶关','益阳','资阳','广安','抚州','伊春','咸宁','黑河','梅州','贺州','双鸭山'," +
		"'潮州','兴安盟','巴中','黔东南','延安','锡林郭勒','黔南','中卫','铜川','张家界','阿克苏','沭阳','阳春'," +
		"'河池','商洛','雅安','汕尾','哈密','铜仁','白山','来宾','防城港','喀什','大兴安岭','仙桃','七台河'," +
		"'固原','海拉尔','潜江','百色','云浮','湘西','阿拉善盟','那曲','甘孜','张北','黔西南','天门'," +
		"'博尔塔拉','崇左','阿坝','海西','神农架','昌都','果洛','黄南','海南','海东','香港','林芝','海北','山南'," +
		"'三沙','玉树','台湾','澳门','阿里','阿拉尔','五指山','日喀则','马来西亚','新加坡','泰国','衢州','阜新'," +
		"'汉中','鹤壁','怀化','济源','郴州','娄底','莱芜','攀枝花','三门峡','邵阳','孝感','阳泉','通化','梧州','钦州','忻州','朔州','吴忠'," +
		"'呼伦贝尔','吕梁','河源','广元','巴彦淖尔市','辽源','丽水','玉林','乌兰察布','景德镇','阳江','永州','眉山','鹤岗','凉山','恩施'";
	
	
	//直营城市
	public static final String zycitys = 
		"'北京', '成都', '重庆', '石家庄', '济南', '青岛','南京', '杭州', '苏州', '无锡', '合肥', " +
		"'武汉', '郑州', '长沙', '福州', '厦门', '南宁', '哈尔滨', '长春', '太原', '大连', '沈阳', " +
		"'上海', '天津', '广州', '深圳', '东莞'";
	
	
	//颜色列表
	public static List<String> colors = new ArrayList<String>();
	public static List<String> getColors() {
		if(colors.size()<=0){
			colors.add("1D8BD1");
			colors.add("F1683C");
			colors.add("2AD62A");
			colors.add("DBDC25");
			colors.add("770077");
			colors.add("66FFFF");
			colors.add("C10066");
			colors.add("AFD8F8");
			colors.add("F6BD0F");
			colors.add("8BBA00");
		}
		return colors;
	}
	
	
//	//菜单Map  k:url  v:id
//	public static HashMap<String,Integer> checkMenuUrlMap = new HashMap<String, Integer>();
	//key 为 menu的action中最后一级，并去掉小版本号  如 action = /intreport/create/229_4  则 key = 229 
	public static HashMap<String,Menu> visitMenuMap = new HashMap<String,Menu>();
	
	/**菜单缓存初始化
	 * 
	 */
	public  static void getAllMenuMap(){
		try {
			MenuService menuService = ServiceLocator.get(MenuService.class);
			List<Menu> menuList = menuService.getAllMenu();
			for (Menu menu : menuList) {
				String url = menu.getAction();
				if(null == url || "".equals(url)){
					continue;
				}
				
//				//deal for checkMenuUrlMap
//				String checkUrl = url;
//				if(checkUrl.contains("_")){
//					checkUrl = checkUrl.substring(0,checkUrl.lastIndexOf("_"));
//				}
//				checkMenuUrlMap.put(checkUrl, menu.getId());
				
				
				//deal for  visitMenuMap
				String urlKey = url.substring(url.lastIndexOf("/")+1);
				if(urlKey.contains("_")){
					urlKey = urlKey.substring(0,urlKey.indexOf("_"));
				}
				
				visitMenuMap.put(urlKey, menu);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	//order_info 里 productId 与业务线对应管理
	private static Map<Integer,String> opMap = new HashMap<Integer, String>();
	public static Map<Integer,String> getOpMap(){
		if(opMap.isEmpty() || null == opMap ){
			opMap.put(100101, "黄页");
			opMap.put(100102, "黄页");
			
			opMap.put(100201, "招聘");
			
			opMap.put(100301, "房产");
			opMap.put(100302, "房产");
			opMap.put(100303, "房产");
			opMap.put(100304, "房产");
			
			opMap.put(100401, "二手市场");
			opMap.put(100101, "二手市场");
			
			opMap.put(100501, "二手车");
			opMap.put(100502, "二手车");
			opMap.put(100503, "二手车");
			opMap.put(100504, "二手车");
			opMap.put(100505, "二手车");
			opMap.put(100506, "二手车");
		}
		return opMap;
	}
	
	
	//业务线对应条件MAP
	private static HashMap<String, String> busLineConditionMap = new HashMap<String, String>();
	
	/**业务线类别关系
	 * @return
	 * @throws Exception
	 */
	public static HashMap<String, String> getBusLineConditionMap()throws Exception{
		if(busLineConditionMap.isEmpty()){
			busLineConditionMap.put("黄页", "disp_cate1_name in('农林牧副渔','招商加盟','休闲娱乐','医疗健康','商务服务','婚庆摄影','家政服务','教育培训','汽车服务','旅游酒店','装修建材','餐饮美食','批发采购','丽人','公共服务')  and  (disp_cate2_name !='二手回收' or  disp_cate2_name is null ) ");
			busLineConditionMap.put("招聘", "disp_cate1_name in('全职招聘','兼职招聘')");
			busLineConditionMap.put("二手市场", "( (disp_cate1_name in ('二手市场', '车辆买卖与服务','票务') and (disp_cate2_name != '二手车' or disp_cate2_name is null) ) or  disp_cate2_name ='二手回收' ) ");
			busLineConditionMap.put("宠物", "disp_cate1_name = '宠物'");
			busLineConditionMap.put("二手车", "disp_cate2_name = '二手车'");
			busLineConditionMap.put("房产", "disp_cate1_name = '房产信息'");
		}
		return busLineConditionMap;
	}
	
	
	//新业务线对应关系(展现)  cate_id  - 业务线
	private static HashMap<Long, String> dispCateIdBusiMap = new HashMap<Long, String>();
	
	/**类别 - 业务线 对应关系
	 * @param productType  1 = 用户业务线   2 = 商业业务线
	 * @throws Exception
	 */
	public  HashMap<Long, String> getDispCateBusiMap(int productType)throws Exception{
		if(dispCateIdBusiMap.isEmpty()){
			 List<NewDisplayCate> allList = newDisplayCateService.getAll();
			 for (NewDisplayCate vo : allList) {
				 if(productType == 1){
					 dispCateIdBusiMap.put(vo.getCate_id(), vo.getBusiness_type());
				 }else  if(productType == 2){
					 dispCateIdBusiMap.put(vo.getCate_id(), vo.getBusiness_type_biz());
				 }
				 
			}
		}
		return dispCateIdBusiMap;
	}
	
	//新业务线对应关系(归属)  cate_id  - 业务线
	private static HashMap<Long, String> belongCateIdBusiMap = new HashMap<Long, String>();
	
	public  HashMap<Long, String> getBelongCateBusiMap(int productType)throws Exception{
		if(belongCateIdBusiMap.isEmpty()){
			 List<NewBelongCate> allList = newBelongCateService.getAll();
			 for (NewBelongCate vo : allList) {
				 if(productType == 1){
					 belongCateIdBusiMap.put(vo.getCate_id(), vo.getBusiness_type());
				 }else  if(productType == 2){
					 belongCateIdBusiMap.put(vo.getCate_id(), vo.getBusiness_type_biz());
				 }
				 
			}
		}
		return belongCateIdBusiMap;
	}
	
	
	
	public static HashMap<String, String> flowSourceDicMap = new HashMap<String, String>(); //流量来源字典 - PC
	
	
	/**获取流量来源字典
	 * 
	 */
	public  static void getFlowSourceDic(){
		try {
			NetFlowSourceService netFlowSourceService = ServiceLocator.get(NetFlowSourceService.class);
			flowSourceDicMap = netFlowSourceService.getDicMap();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	//header cate1 展示默认排序
	public static List<String>  cate1SortList = new ArrayList<String>();
	private  static void initCate1Sort(){
		cate1SortList.add("收入");
		cate1SortList.add("流量");
		cate1SortList.add("信息");
		cate1SortList.add("综合");
		cate1SortList.add("实时");
		cate1SortList.add("指数");
		cate1SortList.add("个人中心");
	}
	
	
	
	//各一级类别下的二级类 排序
	public static Map<String,List<String>>  cate2SortMap = new HashMap<String, List<String>>();
	private  static void initCate2Sort(){
		//收入
		List<String> incomeList  = new ArrayList<String>();
		incomeList.add("收入看板");
		incomeList.add("汇总");
		incomeList.add("精准CPC");
		incomeList.add("置顶");
		incomeList.add("智能");
		incomeList.add("摊销");
		incomeList.add("联盟");
		incomeList.add("赶集");
		cate2SortMap.put("收入", incomeList);
		//流量
		List<String> fluxList  = new ArrayList<String>();
		fluxList.add("流量看板");
		fluxList.add("汇总");
		fluxList.add("业务线");
		fluxList.add("流量分配");
		fluxList.add("来源");
		fluxList.add("ROI");
		fluxList.add("APP");
		fluxList.add("工具");
		fluxList.add("AB测");
		fluxList.add("用户行为");
		cate2SortMap.put("流量", fluxList);
		
		//信息
		List<String> infoList  = new ArrayList<String>();
		infoList.add("信息看板");
		infoList.add("简历看板");
		infoList.add("全站");
		infoList.add("简历");
		infoList.add("分业务线");
		infoList.add("发布");
		infoList.add("其他");
		cate2SortMap.put("信息", infoList);
		
		//综合 -- 暂不需要
		
	}
	
	public static final String cityOperAll = "all";//城市权限常量 - 全部城市权限
	public static final String cityOperZY = "zy";//城市权限常量 - 直营城市权限
	public static final String cityOperQD= "qd";//城市权限常量 - 渠道城市权限
	
	
	static {
		getAllMenuMap();
		getFlowSourceDic();
		initCate1Sort();
		initCate2Sort();
	}
}
